<?php

namespace App\Admin\Controllers;

use App\Admin\Metrics\Agreement;
use App\Admin\Metrics\AssetsWorthTrend;
use App\Admin\Metrics\BannerAgreementCounts;
use App\Admin\Metrics\BannerCompanyCounts;
use App\Admin\Metrics\BannerExpertCounts;
use App\Admin\Metrics\BannerMyAssetsWorth;
use App\Admin\Metrics\BannerMyTodoCounts;
use App\Admin\Metrics\BannerServiceIssueCounts;
use App\Admin\Metrics\BannerMaintenanceRecordCounts;
use App\Admin\Metrics\BannerPaidAgreementCounts;
use App\Admin\Metrics\BannerPendingReviewCounts;
use App\Admin\Metrics\BannerProjectCounts;
use App\Admin\Metrics\CustomerTrend;
use App\Admin\Metrics\ExpertTrend;
use App\Admin\Metrics\OrderTrend;
use App\Admin\Metrics\ProjectOrders;
use App\Admin\Metrics\ProjectTrend;
use App\Admin\Metrics\WorthTrend;
use App\Http\Controllers\Controller;
use App\Models\AdminUser;
use App\Models\MessageRecord;
use App\Models\OrderServiceProfile;
use App\Models\OrderServiceSubmitDetail;
use App\Models\User;
use Dcat\Admin\Admin;
use Dcat\Admin\Http\Controllers\Dashboard;
use Dcat\Admin\Layout\Column;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;
use Dcat\Admin\Widgets\Card;

class HomeController extends Controller
{
    public function index(Content $content): Content
    {
        if (Admin::user()->can('index') && Admin::user()->can('index-list')) {
            return $content
                ->title('仪表盘')
                ->description('掌握你的一切资源')
                ->body(function (Row $row) {
                    // 协议数
                    $row->column(2, new BannerAgreementCounts());
                    // 待审核协议数
                    $row->column(2, new BannerPendingReviewCounts());
                    // 已支付协议数
                    $row->column(2, new BannerPaidAgreementCounts());
                    // 项目数
                    $row->column(2, new BannerProjectCounts());
                    // 专家数
                    $row->column(2, new BannerExpertCounts());
                    // 公司数
                    $row->column(2, new BannerCompanyCounts());

                    $row->column(12, '<hr>');
                    $row->column(12, function (Column $column) {
                        $column->row(function (Row $row) {

                            $row->column(6, function (Column $column) {
                                // 近七天专家趋势
                                $column->row(new ExpertTrend());
                            });
                            $row->column(6, function (Column $column) {
                                // 近七天项目趋势
                                $column->row(new ProjectTrend());
                            });
                            $row->column(6, function (Column $column) {
                                // 劳务协议统计 柱状图
                                $column->row(new Agreement());
                            });
                            $row->column(6, function (Column $column) {
                                // 项目执行状态
                                $column->row(new ProjectOrders());
                            });
                            // $row->column(12, function (Column $column) {
                            //     $column->row(new AssetsWorthTrend());
                            // });
                            // $row->column(12, function (Column $column) {
                            //     $column->row(new AssetsWorthTrend());
                            // });
                        });
                    });
                });
        } else {
            return $content
                ->title('仪表盘')
                ->description('掌握你的一切资源')
                ->body(function (Row $row) {
                    // $row->column(3, new BannerMyAssetsWorth());
                    // // @permissions
                    // // if (Admin::user()->can('home.asset.admin')) {
                    // $row->column(3, new BannerMyTodoCounts());
                    // $row->column(3, new BannerMaintenanceRecordCounts());
                    // $row->column(3, new BannerServiceIssueCounts());
                    // }
                    // // @permissions
                    // if (Admin::user()->can('home.dashboard')) {
                    $row->column(12, '<hr>');
                    // $row->column(12, function (Column $column) {
                    //     $column->row(function (Row $row) {
                    //         $row->column(6, function (Column $column) {
                    //             $column->row(new CustomerTrend());
                    //             // $column->row(new DefectTrend());
                    //         });
                    //         $row->column(6, function (Column $column) {
                    //             $column->row(new OrderTrend());
                    //             // $column->row(new DefectTrend());
                    //         });
                    //         $row->column(12, function (Column $column) {
                    //             $column->row(new AssetsWorthTrend());
                    //         });
                    //     });
                    // });
                });
        }
    }
}
